package com.thirteenClassicsServer.designPattern.test;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author wangzihao10 <wangzihao@kuaishou.com>
 * Created on 2024-08-10
 */
public class CallableTread implements Callable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new CallableTread());
        Thread thread = new Thread(futureTask);
        thread.start();

        try {
            // 获取结果
            System.out.println(futureTask.get());
        } catch (ExecutionException e) {
            // 捕获并处理异常
            System.err.println("发生异常: " + e.getCause().getMessage());
        } catch (InterruptedException e) {
            // 处理线程中断异常
            System.err.println("线程被中断: " + e.getMessage());
        }
    }

    @Override
    public String call() throws Exception {
        throw new Exception("abc");
    }
}
